package com.gxan.dao.impl;

import com.gxan.dao.ResumeDao;
import com.gxan.dbutils.JdbcBuild;
import com.gxan.pojo.Recruitment;
import com.gxan.pojo.RegistrationResults;
import com.gxan.pojo.Resume;

import java.sql.SQLException;
import java.util.List;

public class ResumeDaoImpl extends JdbcBuild implements ResumeDao {
    @Override
    public int addResume(Resume resume) throws SQLException {
        String sql="insert  into `resume`(`job_title`,`job_code`,`job_classification`,`name`,`sex`,`recruitment_type`,`email`,`phone`,`registered_residence`,`address`,`political_landscape`,`id_number`,`graduate_school`,`education_background`,`major`,`work_experience`,`salary_requirement`,`whether_in_office`,`fresh_graduate`,`registration_time`,`personal_resume`,`resume_attachment`,`recommend_the_interview`,`referrer`,`the_recommended_time`,`recommended_Interview_advice`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object params[] = {
                resume.getJob_title(),resume.getJob_code(),resume.getJob_classification(),
                resume.getName(),resume.getSex(),resume.getRecruitment_type(),
                resume.getEmail(),resume.getPhone(),resume.getRegistered_residence(),
                resume.getAddress(),resume.getPolitical_landscape(),resume.getId_number(),
                resume.getGraduate_school(),resume.getEducation_background(),resume.getMajor(),
                resume.getWork_experience(),resume.getSalary_requirement(),resume.getWhether_in_office(),
                resume.getFresh_graduate(),resume.getRegistration_time(),resume.getPersonal_resume(),
                resume.getResume_attachment(),resume.getRecommend_the_interview(),
                resume.getReferrer(),resume.getThe_recommended_time(),resume.getRecommended_Interview_advice()

        };
        return super.executeUpdate(sql,params);
    }

    @Override
    public int delResumeById(String id) throws SQLException {
        String sql="delete from resume  where resume_id = ?";
        Object[] params = {id};
        return super.executeUpdate(sql,params);

    }

    @Override
    public int updateResume(Resume resume) throws SQLException {
        //定义Sql语句
        String sql = "UPDATE resume SET `job_title`= ?,`job_code`= ?,`job_classification`= ?,`name`= ?,`sex`= ?,`recruitment_type`= ?,`email`= ?,`phone`= ?,`registered_residence`= ?,`address`= ?,`political_landscape`= ?,`id_number`= ?,`graduate_school`= ?,`education_background`= ?,`major`= ?,`work_experience`= ?,`salary_requirement`= ?,`whether_in_office`= ?,`fresh_graduate`= ?,`registration_time`= ?,`personal_resume`= ?,`resume_attachment`= ?,`recommend_the_interview`= ?,`referrer`= ?,`the_recommended_time`= ?,`recommended_Interview_advice`= ? where resume_id =?";
        Object params[] = {
                resume.getJob_title(),resume.getJob_code(),resume.getJob_classification(),
                resume.getName(),resume.getSex(),resume.getRecruitment_type(),
                resume.getEmail(),resume.getPhone(),resume.getRegistered_residence(),
                resume.getAddress(),resume.getPolitical_landscape(),resume.getId_number(),
                resume.getGraduate_school(),resume.getEducation_background(),resume.getMajor(),
                resume.getWork_experience(),resume.getSalary_requirement(),resume.getWhether_in_office(),
                resume.getFresh_graduate(),resume.getRegistration_time(),resume.getPersonal_resume(),
                resume.getResume_attachment(),resume.getRecommend_the_interview(),
                resume.getReferrer(),resume.getThe_recommended_time(),resume.getRecommended_Interview_advice(),
                resume.getResume_id()
        };
        return super.executeUpdate(sql,params);

    }

    @Override
    public Integer countResume(Resume resume) throws SQLException {
        //五个条件查询，我这里只写了两个
        if(resume.getName()!=null){
            String sql ="select count(*) from resume where name=? and job_title=? and work_experience =? and recommend_the_interview =? and registration_time=?  ";
            Object params[]={
                    resume.getName(),resume.getJob_title(),
                    resume.getWork_experience(),resume.getRecommend_the_interview(),
                    resume.getRegistration_time()};
            return super.findAllForInt(sql,params);
        }else{
            //无条件查询
            String sql="select count(*) from resume ";
            return super.findAllForInt(sql,null);
        }
    }

    @Override
    public List<Resume> queryResumeList(Integer param01, Integer param02, Resume resume) throws SQLException {
        //五个条件查询，我这里只写了两个
        if(resume.getName()!=null){
            String sql ="select * from resume where name=? and job_title=? and work_experience =? and recommend_the_interview =? and registration_time=?  limit ? , ?  ";
            Object params[]={
                    resume.getName(),resume.getJob_title(),
                    resume.getWork_experience(),resume.getRecommend_the_interview(),
                    resume.getRegistration_time(), param01,param02};
            return super.queryListEntity(Resume.class,sql,params);
        }else{
            //无条件查询
            String sql="select * from resume limit ? , ?  ";
            Object params[]={param01,param02};
            return super.queryListEntity(Resume.class,sql,params);
        }

    }

    @Override
    public RegistrationResults queryRegistrationResultsById(Integer id) throws SQLException {
        String sql="select * from registrationresults where resume_id =?";
        Object params[] = {id};
        return super.queryEntity(RegistrationResults.class,sql,params);
    }

    @Override
    public int updateRegistrationResults(RegistrationResults registrationResults) throws SQLException {
        String sql ="update registrationresults set recommend_the_interview=?,first_interviewer=?,first_time=?,first_evaluation=?,second_interviewer=?,second_time=?,second_evaluation=?,third_interviewer=?,third_time=?,third_evaluation=? where interview_result_id=?";
        Object params[] = {
                registrationResults.getRecommend_the_interview(),
                registrationResults.getFirst_interviewer(),
                registrationResults.getFirst_time(),
                registrationResults.getFirst_evaluation(),
                registrationResults.getSecond_interviewer(),
                registrationResults.getSecond_time(),
                registrationResults.getSecond_evaluation(),
                registrationResults.getThird_interviewer(),
                registrationResults.getThird_time(),
                registrationResults.getThird_evaluation(),
                registrationResults.getInterview_result_id()
        };
        return super.executeUpdate(sql,params);
    }

    @Override
    public int updateResumeById(String recommend_the_interview, Integer id) throws SQLException {
        String sql="update resume set recommend_the_interview=? where resume_id =? ";
        Object params[]={recommend_the_interview,id};
        return super.executeUpdate(sql,params);
    }

    @Override
    public int employedRegistrationResultsById(Integer resume_id) throws SQLException {
        String sql="update resume set recommend_the_interview='录用' where resume_id =? ";
        Object params[]={resume_id};
        return super.executeUpdate(sql,params);
    }
}
